<include file="../header"/>
<head>
    <link rel="stylesheet" href="/assets/schoolirs/css/countdown.css?version=1">
</head>
<body>
<div class="wraper">

    <div class="top">
        <p>
            <a onclick="javascript:history.go(-1);" class="iconfont icon-zuo pull-left"></a>
            <a href="javascript:void(0);" class="order-all pull-left">确认订单</a>
        </p>
        <input type="hidden" id="send_price" value="{BEESCRM:$sendPrice}">
        <input type="hidden" id="close_time" value="{BEESCRM:$closeTime}">
        <input type="hidden" id="orderId" value="{BEESCRM:$order_id}">
        <input type="hidden" id="irsId" value="{BEESCRM:$irs_id}">
    </div>
    <div class="tips">
        温馨提示：付款后不能退单,请在<strong id="minute_show">0分</strong>
        <strong id="second_show">0秒</strong>内完成付款</br>
    </div>

    <div class="order-info topnone">
        <div class="lists">就餐地点:{BEESCRM:$window_name}({BEESCRM:$refectory_name})</div>
    </div>
    <div class="order-info">
        <div class="lists tb-mode">
            <div class="tb-cell list-left">就餐时间</div>
            <div class="tb-cell list-right" style="width: 15%;">{BEESCRM:$eatTime}</div>
        </div>
    </div>
    <div class="order-info">
        <div class="lists tb-mode" id="paytype">
            <div class="tb-cell list-left">支付方式</div>
            <div class="tb-cell list-right">
                <a href="javascript:void(0);" class="paymethod">{BEESCRM:$pay_method}<span
                        class="iconfont icon-you"></span></a>
            </div>
        </div>
    </div>
    <if condition="$hasBalconyRight eq 1">
        <div class="order-info">
            <div class="lists tb-mode">
                <div class="tb-cell list-left">桌号</div>
                <div class="tb-cell list-right">
                    <if condition="$hasBalcony eq 0">
                        <a href="javascript:void(0);" class="disbalcony" data-type="1">不预定<span
                                class="iconfont icon-you text-gray"></span></a>
                    </if>
                    <if condition="$hasBalcony eq 1">
                        <a href="javascript:void(0)" class="abledbalcony" data-type="1">
                            <if condition="$hasOrderBalcony eq 1">
                                {BEESCRM:$balconyInfo.balcony_name}
                            </if>
                            <if condition="$hasOrderBalcony eq 0">
                                不预定
                            </if>
                            <span class="iconfont icon-you text-gray"></span>
                        </a>
                    </if>
                </div>
            </div>
        </div>
    </if>


    <div class="order-lists lists">
        <div class="lists tb-mode">
            <div class="tb-cell list-left">餐品列表</div>
        </div>
        <volist name="goodList" id="vo">
            <div class="lists tb-mode foods">
                <a href="javascript:void(0);" class="tb-cell list-left">
                    <div class="img-box"><img src="{BEESCRM:$vo['goods_logo']}"></div>
                </a>
                <a href="javascript:void(0);" class="tb-cell list-center">
                    <p>{BEESCRM:$vo['goods_name']}</p>
                    <p class="prize">{BEESCRM:$vo['goods_price']}元</p>
                </a>
                <div class="tb-cell list-right">
                    <div class="tb-mode amount" style="text-align: center;border:0;">
                        {BEESCRM:$vo['goods_num']}<span class="wd-good" style="display: none;">x1</span>
                    </div>
                </div>
            </div>
        </volist>
        <div class="lists tb-mode">
            <div class="tb-cell list-right" style="line-height: 1.5;">
                <p id="sendPrice">餐盒费：0元</p>
                <p>积分优惠：0元</p>
                <p>
                    总价：<span class="num" id="orderPrice">{BEESCRM:$data.moneySum}元</span>
                    <input type="hidden" value="{BEESCRM:$data.moneySum}" id="orderAmount">
                </p>
            </div>
        </div>

        <div class="lists bottom-none">
            <input value="" placeholder="特殊需要请备注" id="memo"/>
        </div>
    </div>
    <input type="hidden" class="restaurant_id" value="{BEESCRM:$redectory_id}">
    <input type="hidden" class="window_id" value="{BEESCRM:$window_id}">
    <input type="hidden" id="irs_id" value="{BEESCRM:$res_id}">
    <input type="hidden" id="takeout" value="{BEESCRM:$takeout}">
    <input type="hidden" id="amount" value="{BEESCRM:$amount}">
    <input type="hidden" id="freight" value="{BEESCRM:$freight}">
    <input type="hidden" id="pay_type" value="{BEESCRM:$pay_type}">
    <div class="btn-box">
        <a href="javascript:void(0)" class="btn green-btn pay-btn" data-order_id="{BEESCRM:$order_id}">
            <if condition="$pay_type eq 4">
                确认挂账
            </if>
            <if condition="$pay_type eq 1">
                立即付款
            </if>

        </a>
    </div>
    <div class="pop-box " id="Opacity">
        <div class="pop-hint">
            <div class="text-center pop-title font-16">请选择支付方式</div>
            <div class="Radio">
                <div class="box-radio">
                    <div class="line-radio"><input type="radio" id="a1" value="1" name="a" class="radio"
                                                   checked="checked"><label for="a1">微信支付</label></div>
                    <div class="line-one" style="margin: 15px"></div>
                    <if condition="$onAccountRight eq 1">
                        <div class="line-radio"><input type="radio" id="a2" value="4" name="a" class="radio"><label
                                for="a2">挂账</label></div>
                    </if>

                    <!--<div class="line-radio"><input type="radio" id="a3" value="" name="a" class="radio"><label-->
                    <!--for="a3">一卡通支付</label></div>-->
                </div>
            </div>
        </div>
    </div>

    <div class="pop-box " id="balcony_time">
        <div class="pop-hint">
            <div class="text-center pop-title font-16">选择包厢使用时间</div>
            <div class="Radio">
                <div class="box-radio">
                    <div class="line-radio"><input type="radio" id="b1" value="30" name="b" class="radio"
                                                   checked="checked"><label for="b1">30分钟付</label></div>
                    <div class="line-one" style="margin: 15px"></div>

                    <div class="line-radio"><input type="radio" id="b2" value="60" name="b" class="radio"><label
                                for="b2">60分钟</label></div>
                    <div class="line-one" style="margin: 15px"></div>

                    <div class="line-radio"><input type="radio" id="b3" value="90" name="b" class="radio"><label
                    for="b3">90分钟</label></div>
                    <div class="line-one" style="margin: 15px"></div>

                    <div class="line-radio"><input type="radio" id="b4" value="120" name="b" class="radio"><label
                            for="b4">120分钟</label></div>
                </div>
            </div>
        </div>
    </div>
</div>

<include file="../commonJS"/>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="/assets/schoolirs/js/order.js?version=1"></script>
<script src="/assets/schoolirs/js/countdown.js?version=1"></script>
<script>
    $('.classify').click(function () {
        $('.menu-lists').addClass('show-menu');
    })
    $('.close').click(function () {
        $('.menu-lists').removeClass('show-menu');
    })
</script>

<script>
    var closeTime = $("#close_time").val();
    var irsId = $("#irs_id").val();
    var orderId = $("#orderId").val();


    //增减外带份数
    $(".change-num-btn").on('click', function () {
        var s = $(this).data('status');
        var num = $("#wd-num").val();
        var sendPrice = $("#send_price").val();
        if (s == 'sub') {//-
            var sub_num = parseInt(num) - 1;
            if (sub_num >= 1) {
                upWdOrder(sub_num, orderId, sendPrice);

            }
        } else if (s == 'plus') {//+
            var plus_num = 1 + parseInt(num);
            upWdOrder(plus_num, orderId, sendPrice);
        }

    });

    //修改外带订单
    function upWdOrder(num, orderId, sendPrice) {
        var info = {};
        info.orderId = orderId;
        info.num = num;
        info.sendPrice = sendPrice;
        $.ajax({
            'url': "/schoolirs/Order/carryOrder?res_id=" + irsId,
            'data': info,
            'dataType': 'json',
            'type': 'POST',
            'async': false,
            success: function (data) {
                if (data.status == 'S') {
                    $("#wd-num").val(data.num);
                } else {
                    fm.alert(data.message);
                }
            }
        });
    }


    //是否为外带订单
    function upOrder(besides, sendPrice) {
        var orderId = $("#orderId").val();
        var info = {};
        info.orderId = orderId;
        info.besides = besides;
        info.sendPrice = sendPrice;
        $.ajax({
            'url': "/schoolirs/Order/besidesOrder?res_id=" + irsId,
            'data': info,
            'dataType': 'json',
            'type': 'POST',
            'async': false,
            success: function (data) {
                if (data.status == 'S') {
                    var orderAmount = $("#orderAmount").val();
                    if (besides == 1) {
                        var orderPrice = parseFloat(orderAmount) + parseFloat(data.sendPrice);
                        $("#sendPrice").html("餐盒费:" + data.sendPrice + "元");
                        $("#orderPrice").html(orderPrice.toFixed(2) + '元');
                    } else {
                        $("#sendPrice").html("餐盒费:0元");
                        $("#orderPrice").html(orderAmount + '元');
                    }
                } else {
                    fm.alert(data.message);
                }
            }
        });
    }

    //选择口味
    $("#flavor_inp").change(function () {
        //修改订单口味
        var info = {};
        info.orderId = orderId;
        info.flavor = $("#flavor_inp option:selected").val();
        ;
        $.ajax({
            'url': "/schoolirs/Order/flavorOrder?res_id=" + irsId,
            'data': info,
            'dataType': 'json',
            'type': 'POST',
            'async': false,
            success: function (data) {
                if (data.status == 'S') {
                } else {
                }
            }
        });
    })


    //选择支付方式
    $('#paytype').click(function () {
        $('#Opacity').show();
    })
    $('#Opacity').on('click', '.line-radio', function () {
        $('#Opacity').hide();
        var html = $(this).text() + '<span class="iconfont icon-you"></span>';
        $('.paymethod').html(html);
        if ($('input:radio[name="a"]:checked').val() == 1) {
            $('.pay-btn').text('立即付款');
            $('#pay_type').val('1');
        } else if ($('input:radio[name="a"]:checked').val() == 4) {
            $('.pay-btn').text('确定挂账');
            $('#pay_type').val('4');
        } else {
            $('#pay_type').val('1');
            $('.pay-btn').text('立即付款');
        }
    });



    $(document).on('click', '.abledbalcony', function () {
        $('#balcony_time').show();
    });
    $('#balcony_time').on('click', '.line-radio', function () {
        $('#balcony_time').hide();

        var balcony_time = $('input:radio[name="a"]:checked').val();



        if (!balcony_time) {
            fm.alert('请选择使用包厢时间');
            return;
        }

        hasFreeBalcony(balcony_time);

    });

    function hasFreeBalcony(time) {
        var time = time;
        var type = $('#pay_type').val();
        var windowId = $('.window_id').val();
        var info = {};
        var json = {};
        info.window_id = windowId;
        info.order_id = orderId;
        $.ajax({
            'url': "/Schoolirs/Order/hasFreeBalcony?res_id=" + irsId,
            'data': info,
            'dataType': 'json',
            'type': 'POST',
            'async': false,
            success: function (data) {
                if (data.status == 'S') {

                    var url = "/Schoolirs/Order/choseBalcony?window=" + windowId + "&type=" + type + "&res_id=" + irsId + "&order_id=" + orderId;

                    location.href = url;
                } else {
                    fm.alert(data.message);
                    return false;
                }
            }
        });
    }



</script>
</body>
</html>
